<?php
namespace Home\Controller;
class RegController extends HomeController {
    public function index(){
        $this->display();
    }
public function checkEmail(){
    	$user = M('user');
        $userinfo = M('user_info');
        $email = $_POST['email'];
        $password = $_POST['password'];
        $yzm = $_POST['yzm'];
        if($_SESSION['emailyzm'] != $_POST['yzm']){
            echo json_encode($_SESSION['emailyzm']);
            echo json_encode($_POST['yzm']);

            return false;
        }
        if($email == null || $password == null){
            echo json_encode('empty');
            return false;
        }
        $user->create();
        $id = $user->add();
        if($id>0){
            $_POST['ui_id']=$id;
            $userinfo->create();
            $userinfo->add();
            session('email',$_POST['email']);
            session('password',$_POST['password']);
            session('uid', $id);
            echo json_encode('success');
        }else{
            echo json_encode('fail');
            return false;
        }
    }


        
        // $data = $user->where($where)->find();
        // if(empty($data['email'])){
        //     $user = M('user');
        //     $user->create();
        //     if($user->add()>0){
        //        $this->index();
        //     }else{
        //         echo json_encode('n');
        //     }
        // }else{
        //     echo json_encode('h');
        // }
	
    public function emailyzm(){
        // var_dump($_POST);die;
        // session_start();
        $email = $_POST['email'];
        $user = M('user');
        $where['email'] = array('eq',$email);
        $data = $user->where($where)->select();
        if($data>0){
            echo json_encode('exist');
            // die;
            return false;
        }else{            
        $yzm = rand(1000,9999);
        $_SESSION['emailyzm'] = $yzm;
        sendMail("$email", 'dota2Max绑定邮箱验证',"$yzm");
        echo json_encode('send');
        }
    }

}